package com.tanhua.server.controller;

/**
 * @Author: cl
 * @Date: 2022/5/3 - 05 - 03
 * @Description:
 */

import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.MessagesService;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 缘分匹配模块
 */
@RestController
@RequestMapping("tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    @Autowired
    private MessagesService messagesService;

    /**
     * 获取今日佳人
     *
     * @return
     */
    @GetMapping("/todayBest")
    public ResponseEntity toDayBest() {

        TodayBest todayBest = tanhuaService.toDayBest();
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 推荐缘分用户分页展示
     *
     * @param recommendUserDto
     * @return
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto recommendUserDto) {

        PageResult page = tanhuaService.recommendation(recommendUserDto);
        return ResponseEntity.ok(page);

    }

    /**
     * 通过id查询佳人信息
     *
     * @param userId
     * @return
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity getPersonalInfo(@PathVariable("id") Long userId) {

        TodayBest todayBest = tanhuaService.getPersonalInfo(userId);
        return ResponseEntity.ok(todayBest);

    }

    /**
     * 通过id查询用户问题
     *
     * @param userId
     * @return
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity getQusetion(Long userId) {

        String questions = tanhuaService.getQusetion(userId);
        return ResponseEntity.ok(questions);
    }

    /**
     * 根据接收方的id发送信息
     *
     * @param map
     * @return
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity sendMessage(@RequestBody Map map) {

        //前端传过来的userId是Integer类型
        String str = map.get("userId").toString();
        Long userId = Long.valueOf(str);//接收方的id
        String reply = map.get("reply").toString();
        tanhuaService.sendMessage(userId, reply);
        return ResponseEntity.ok("发送成功！");
    }

    /**
     * 获取选择喜欢和不喜欢的列表
     *
     * @return
     */
    @GetMapping("/cards")
    public ResponseEntity getLikeList() {

        List<TodayBest> list = tanhuaService.getLikeList();
        return ResponseEntity.ok(list);
    }

    /**
     * 右滑动喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId) {

        tanhuaService.love(likeUserId);
        return ResponseEntity.ok("喜欢成功");
    }

    /**
     * 左滑动不喜欢
     *
     * @param likeUserId
     * @return
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity unLove(@PathVariable("id") Long likeUserId) {

        tanhuaService.unLove(likeUserId);
        return ResponseEntity.ok("喜欢成功");
    }

    /**
     * 通过性别和距离搜索附近得人
     *
     * @param gender
     * @param distance
     * @return
     */
    @GetMapping("/search")
    public ResponseEntity searchNearUser(String gender,
                                         @RequestParam(defaultValue = "2000") String distance) {

        List<NearUserVo> list = tanhuaService.searchNearUser(gender, distance);
        return ResponseEntity.ok(list);
    }

}
